package com.example.exp2019_4;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.ScaleAnimation;
import android.widget.ImageView;
import android.widget.RelativeLayout;

public class MainActivity extends AppCompatActivity{


    //动画对象
    private ImageView imageView;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.ll_touch);
        imageView = (ImageView)findViewById(R.id.test);
        imageView.setBackgroundResource(R.drawable.frame);

        //（3）	长按小人图像，先缩小，再放大，然后旋转消失
        imageView.setOnLongClickListener(new View.OnLongClickListener() {
            public boolean onLongClick(View view) {
//                ScaleAnimation animation=new ScaleAnimation(1.0f, 0.5f, 1.0f, 0.5f,
//			             Animation.RELATIVE_TO_PARENT, 0.5f, Animation.RELATIVE_TO_SELF, 0);
//                //设置动画显示时间
//                animation.setDuration(3000);
//                imageView.setAnimation(animation);
//                AlphaAnimation anim1=new AlphaAnimation(1, 0);
//                anim1.setDuration(1000);
//                anim1.setRepeatCount(2);
//                imageView.setAnimation(anim1);
                //根据xml文件创建动画对象
                Animation animation= AnimationUtils.loadAnimation(MainActivity.this, R.anim.complex);
                //animation.setFillAfter(true);  //保持最后的动画结果
                //启动显示动画
                imageView.startAnimation(animation);
                return true;
            }
        });

        relativeLayout.setOnTouchListener(new MyOnTouch());
    }

}
